from pydantic import BaseModel, ConfigDict


class SystemConstants(BaseModel):
    model_config = ConfigDict(frozen=True)

    ROOT_NODE_ID: int = 0
    DEFAULT_PASSWORD: str = "123456"
    ROOT_ROLE_CODE: str = "ROOT"
    SYSTEM_CONFIG_IP_QPS_LIMIT_KEY: str = "IP_QPS_THRESHOLD_LIMIT"


class JwtClaimConstants(BaseModel):
    model_config = ConfigDict(frozen=True)

    TOKEN_TYPE: str = "tokenType"
    USER_ID: str = "userId"
    DEPT_ID: str = "deptId"
    DATA_SCOPE: str = "dataScope"
    AUTHORITIES: str = "authorities"


class RedisRateLimiterConstants(BaseModel):
    model_config = ConfigDict(frozen=True)

    IP: str = "rate_limiter:ip:{}"


class RedisLockConstants(BaseModel):
    model_config = ConfigDict(frozen=True)

    RESUBMIT: str = "lock:resubmit:{}:{}"


class RedisAuthConstants(BaseModel):
    model_config = ConfigDict(frozen=True)

    ACCESS_TOKEN_USER: str = "auth:token:access:{}"
    REFRESH_TOKEN_USER: str = "auth:token:refresh:{}"
    USER_ACCESS_TOKEN: str = "auth:user:access:{}"
    USER_REFRESH_TOKEN: str = "auth:user:refresh:{}"
    BLACKLIST_TOKEN: str = "auth:token:blacklist:{}"


class RedisCaptchaConstants(BaseModel):
    model_config = ConfigDict(frozen=True)

    IMAGE_CODE: str = "captcha:image:{}"
    SMS_LOGIN_CODE: str = "captcha:sms_login:{}"
    SMS_REGISTER_CODE: str = "captcha:sms_register:{}"
    MOBILE_CODE: str = "captcha:mobile:{}"
    EMAIL_CODE: str = "captcha:email:{}"


class RedisSystemConstants(BaseModel):
    model_config = ConfigDict(frozen=True)

    CONFIG: str = "system:config"
    ROLE_PERMS: str = "system:role:perms"


class RedisConstants(BaseModel):
    model_config = ConfigDict(frozen=True)

    RateLimiter: RedisRateLimiterConstants = RedisRateLimiterConstants()
    Lock: RedisLockConstants = RedisLockConstants()
    Auth: RedisAuthConstants = RedisAuthConstants()
    Captcha: RedisCaptchaConstants = RedisCaptchaConstants()
    System: RedisSystemConstants = RedisSystemConstants()


class SecurityConstants(BaseModel):
    model_config = ConfigDict(frozen=True)

    LOGIN_PATH: str = "/api/v1/auth/login"
    BEARER_TOKEN_PREFIX: str = "Bearer "
    ROLE_PREFIX: str = "ROLE_"


# 实例化常量（全局单例）
SYSTEM_CONSTANTS = SystemConstants()
JWT_CLAIM_CONSTANTS = JwtClaimConstants()
REDIS_CONSTANTS = RedisConstants()
SECURITY_CONSTANTS = SecurityConstants()
